package com.xayy.health.core.websocket;

/**
 * @description: WebSocket的配置类 开启对WebSocket的支持
 * @author: liyz
 * @createDate: 2023/10/30 0030
 * @version: 1.0
 */

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.*;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer {

    /**
     * 注册stomp的端点
     * 注册一个STOMP协议的节点，并映射到指定的URL
     */
    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic");
        config.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/websocket-health").setAllowedOriginPatterns("http://localhost:8010", "http://192.168.0.123:8010").withSockJS();
    }



    @Override
    public void configureWebSocketTransport(WebSocketTransportRegistration registration) {

        registration.setMessageSizeLimit(500*1024).setSendBufferSizeLimit(50*1024*1024).setSendTimeLimit(2*60*1000);
    }
}